package com.hellogood.yaohuo.server.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hellogood.yaohuo.server.db.DBHelper;
import com.hellogood.yaohuo.shared.entity.Detail;

public class ZyDetailDAO extends DBHelper {
	@Override
	public List<?> initializeObject(ResultSet rs) throws SQLException {
		List<Detail> detailList = new ArrayList<Detail>();
		if (rs != null) {
			while (rs.next()) {
				Detail d = new Detail();
				d.setBillNo(rs.getString("ZybillNo") == null ? "" : rs.getString("ZybillNo").trim());
				d.setZyCode(rs.getString("ZyCode") == null ? "" : rs.getString("ZyCode").trim());
				d.setZyName(rs.getString("zyName") == null ? "" : rs.getString("zyName").trim());
				d.setCounts(rs.getInt("Counts"));
				d.setRemark(rs.getString("Remark") == null ? "" : rs.getString("Remark").trim());
				detailList.add(d);
			}
		}
		return detailList;
	}

	@SuppressWarnings("unchecked")
	public List<Detail> getDetailByBillNo(String billNo) {
		List<Detail> list = new ArrayList<Detail>();

		String sql = "SELECT d.*,(SELECT ziyouName FROM ziyou WHERE ziyouCode = d.ZyCode) AS zyName FROM ZyDetail d WHERE d.ZybillNo = '" + billNo + "' ORDER BY d.ZyCode";
		list = (List<Detail>) super.query(sql);
		return list;
	}
}
